﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpBasic.链式编程
{
    public class 链式编程2
    {

        public static void DoTest3()
        {
            MyPro myPro = new MyPro();
            string result = myPro.SetId("001").SetName("002").GetInfo();
            Console.WriteLine(result);
        }

        public static void DoTest2()
        {
            MyPro myPro = new MyPro();
            myPro.Id = "001";
            myPro.Name = "002";

            Console.WriteLine(myPro.GetInfo());
        }

        public static void DoTest()
        {
            String tmpA = "abcdefg";
            int cIndex = tmpA.Replace("a", "aa").IndexOf("c");
            Console.WriteLine(cIndex);
        }
    }

    public class MyPro
    {
        /// <summary>
        /// 名称
        /// </summary>
        public String Name { get; set; }

        /// <summary>
        /// ID值
        /// </summary>
        public String Id { get; set; }


        /// <summary>
        /// 设置名称
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public MyPro SetName(string name)
        {
            Name = name;
            return this;
        }

        /// <summary>
        /// 设置Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MyPro SetId(string id){
            Id = id;
            return this;
        }

        /// <summary>
        /// 得到信息
        /// </summary>
        /// <returns></returns>
        public String GetInfo()
        {
            return $"{Id}-{Name}";
        }
    }

}
